<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .a {
            width: 300px;
            height: 300px;
            background-color: #f00;
            margin: 10px auto;
        }

        .box {
            width: 500px;
            height: 400px;
            background-color: #000;
            overflow: hidden;
            position: relative;
        }
    </style>
</head>

<body>

    <div class="box">
        <div class="a"></div>
    </div>


    <script>

        // offsetLeft  /  offsetTop  
        //    距离最近的具有定位的元素的距离

        var oA = document.querySelector('.a');

        console.log(oA.offsetLeft, oA.offsetTop);

    </script>

</body>

</html>